package test01

class Point(val x: Int, val y: Int)


trait Rectangular {

  def topLeft: Point

  def bottomRight: Point

  def left = topLeft.x

  def right = bottomRight.x

  def width = right - left
}

// topLeft 重构了 def topLeft: Point
// left、right、width 有初始化值
class Rectangle(var topLeft: Point, var bottomRight: Point) extends Rectangular {

}

object Rectangle {

  def main(args: Array[String]): Unit = {

    val rect = new Rectangle(new Point(1, 1) ,new Point(10, 10))

    println("rect.left==>" + rect.left)
    println("rect.right==>" + rect.right)
    println("rect.width==>" + rect.width)

  }

}